/*
    3D Office Environment
    Copyright (C) 2011  Till Merker

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/

#include "globals.h"
#include <dlfcn.h>

bool initialized = false;
glXGetProcAddress_func OE_glXGetProcAddress = 0;
glBindFramebuffer_func OE_glBindFramebuffer = 0;


glXFuncPtr getProcAddress( const char* name )
{
    glXFuncPtr ret = 0;
    if( OE_glXGetProcAddress != 0 )
	ret = OE_glXGetProcAddress( ( const GLubyte* ) name );
    if( ret == 0 )
	ret = ( glXFuncPtr ) dlsym( RTLD_DEFAULT, name );
    return ret;
}

void initGLfuncs() {
    if(!initialized) {
	OE_glXGetProcAddress = (glXGetProcAddress_func) getProcAddress( "glXGetProcAddress" );
	OE_glBindFramebuffer = (glBindFramebuffer_func) getProcAddress( "glBindFramebufferEXT" );
	initialized = true;
    }
}